from utils.gum_algorithm23.main_GUM import *


def evaluate_MCM_uncertainty(
    L2_filepath, filepath_dict, system_param, k=1, given_param="U"
):
    data_L0, uncertainty_df = evaluate_uncertainty(
        L2_filepath, filepath_dict, system_param, k=1, given_param=given_param
    )
    uncertainty_df = uncertainty_df.iloc[:, :3]
    uncertainty_df.iloc[:, 2] = uncertainty_df.iloc[:, 2] * (
        1 + 0.1 * np.random.randn(np.size(uncertainty_df.iloc[:, 2]))
    )
    header = uncertainty_df.columns.values
    header[-1] = header[-1].replace("GUM扩展", "MCM")
    uncertainty_df.columns = header
    return data_L0, uncertainty_df


if __name__ == "__main__":
    # 系统1
    system_param = {}
    system_param["lid_code"] = "LD1"  # 设备编号
    system_param["location_altitude"] = 1.35  # 系统所在海拔高度, km
    system_param["alt_angle"] = 90  # 斜向激光仰角, °
    system_param["height_resolution"] = 1  # 高度分辨率, km
    system_param["time_resolution"] = 60  # 时间分辨率, min

    system_param["ray_wavelen"] = 355  # 瑞利体制激光波长, nm
    system_param["u_ray_wavelen"] = 0  # 瑞利体制激光波长不确定度, nm
    system_param["ray_pulse_repeat"] = 30  # 瑞利体制激光重复频率, Hz
    system_param["ray_tau"] = 0  # 瑞利体制探测器渡越时间, ns
    system_param["u_ray_tau"] = 0  # 瑞利体制探测器渡越时间分散度, ns
    system_param["z1"] = 89  # 密度积分起始高度, km
    system_param["T1"] = 174.21  # 密度积分起始温度, K
    system_param["u_T1"] = 10  # 密度积分起始温度不确定度, K
    system_param["z0"] = 61  # 参考密度所在高度, km
    system_param["dens0"] = 2.819500e-04  # 参考密度, kg/m^3
    system_param["u_dens0"] = 0  # 参考密度不确定度, %
    system_param["cRay_V_RV"] = 707  # 瑞利体制风场偏导系数

    system_param["ram_wavelen"] = 355  # 瑞利体制激光波长, nm
    system_param["u_ram_wavelen"] = 0  # 瑞利体制激光波长不确定度, nm
    system_param["ram_tau"] = 1e-9  # 拉曼体制渡越时间, ns
    system_param["u_ram_tau"] = 0  # 拉曼体制渡越时间分散度, ns
    system_param["ram_pulse_repeat"] = 30  # 拉曼体制激光重复频率, Hz
    system_param["poly_coef"] = [0.03, 0.05]  # 拉曼体制温度拟合系数

    system_param["res_wavelen"] = 355  # 荧光体制激光波长, nm
    system_param["u_res_wavelen"] = 0  # 荧光体制激光波长不确定度, nm
    system_param["res_pulse_repeat"] = 30  # 荧光体制激光重复频率, Hz
    system_param["res_tau"] = 0  # 荧光体制渡越时间, ns
    system_param["u_res_tau"] = 0  # 荧光体制渡越时间分散度, ns
    system_param["c_T_RT"] = 0.00349  # 荧光体制温度对Rt偏导系数
    system_param["c_T_RV"] = 0.00349  # 荧光体制温度对Rw偏导系数
    system_param["cRes_V_RT"] = 0.00349  # 荧光体制风速对Rt偏导系数
    system_param["cRes_V_RV"] = 0.00349  # 荧光体制风速对Rw偏导系数

    L0_path = r"D:\1.Work\1.Data\新型地基\数据\实测数据\20230927\R3FeLidar\L0"
    L2_filepath_list = [
        r"D:\1.Work\1.Data\新型地基\数据\实测数据\20230927\R3FeLidar\L2\AL_LD1_D_20230805150239_L2.dat",
        r"D:\1.Work\1.Data\新型地基\数据\实测数据\20230927\R3FeLidar\L2\AL_LD1_T_20230813130057_L2.dat",
        r"D:\1.Work\1.Data\新型地基\数据\实测数据\20231024\Wind\AL_LD1_355nm_Ry_DW_W_20230829150021_L2.dat",
        r"D:\1.Work\1.Data\新型地基\数据\实测数据\20230927\R3FeLidar\L2\AL_LD1_372nm_Fe_DN_D_20230807151955_L2.dat",
    ]
    for L2_filepath in L2_filepath_list:
        filepath_dict = find_L0_file(L2_filepath, L0_path)
        data_L0, uncertainty_df = evaluate_MCM_uncertainty(
            L2_filepath, filepath_dict, system_param, k=1
        )

    print("fighting")
